#include <cellcsp.h>
#include <string>
#include <stdio.h>
#include <csp_debug.h>
#include <ProcessStats.h>
#include "../../shared/poison_test.h"

int main(){


	char *collector_file  = "./tasks/poison_collector_process";
	char *collector_alias = "poison_collector_process";

	char *gang_file = "./tasks/poison_w_gang_process";
	char *gang_alias = "poison_w_gang_process";

	char *solo_file  = "./tasks/poison_w_solo_process";
	char *solo_alias = "poison_w_solo_process";

	
	CSPConfig conf;

	conf.add_csp_program(collector_file, collector_alias );
	conf.add_csp_program(gang_file, gang_alias);
	conf.add_csp_program(solo_file, solo_alias);

	CellCSP_start(conf);


	ProcessStats* stats = ProcessStats::Instance();	



	CSPProcess collector(collector_alias);
	stats->RegisterExpectedRes(
		collector.GetProcessComposition(), COLLECTOR_RET_STATUS);

	CSPProcess solo(solo_alias);
	stats->RegisterExpectedRes(
		solo.GetProcessComposition(), SOLO_RET_STATUS);

	CSPProcess gang0(gang_alias);
	CSPProcess gang1(gang_alias);
	CSPProcess gang2(gang_alias);
	CSPProcess gang3(gang_alias);
	CSPProcess gang4(gang_alias);
	CSPProcess gang5(gang_alias);
	CSPProcess gang6(gang_alias);
	CSPProcess gang7(gang_alias);
	CSPProcess gang8(gang_alias);
	CSPProcess gang9(gang_alias);

	stats->RegisterExpectedRes(gang0.GetProcessComposition(), GANG_RET_STATUS);
	stats->RegisterExpectedRes(gang1.GetProcessComposition(), GANG_RET_STATUS);
	stats->RegisterExpectedRes(gang2.GetProcessComposition(), GANG_RET_STATUS);
	stats->RegisterExpectedRes(gang3.GetProcessComposition(), GANG_RET_STATUS);
	stats->RegisterExpectedRes(gang4.GetProcessComposition(), GANG_RET_STATUS);
	stats->RegisterExpectedRes(gang5.GetProcessComposition(), GANG_RET_STATUS);
	stats->RegisterExpectedRes(gang6.GetProcessComposition(), GANG_RET_STATUS);
	stats->RegisterExpectedRes(gang7.GetProcessComposition(), GANG_RET_STATUS);
	stats->RegisterExpectedRes(gang8.GetProcessComposition(), GANG_RET_STATUS);
	stats->RegisterExpectedRes(gang9.GetProcessComposition(), GANG_RET_STATUS);




	Parallel par( &collector, &solo, 
			&gang0, &gang1, &gang2, &gang3, &gang4, 
			&gang5, &gang6, &gang7, &gang8, &gang9, NULL) ;

	int n_procs = 12;
	stats->SetExpectedTerminatedProcesses(n_procs);

	printf("poison_test.Run() with %i processes.\n", n_procs);
	par.Run();
	

	CellCSP_end();

	vector<CSPProcess*> *procs = par.GetProcs();
	printf("%i terminated processes.\n", (int) procs->size());

	stats->Check();

	printf("poison_test terminated\n");
	
	return 0;
}
